package cn.bdqn.services.dept.service.impl;
import cn.bdqn.model.pojo.Menu;
import cn.bdqn.model.pojo.Role;
import cn.bdqn.model.pojo.SysUserinfo;
import cn.bdqn.services.dept.mapper.SysUserinfoMapper;
import cn.bdqn.services.dept.service.SysUserinfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("sysUserinfoService")
public class SysUserinfoServiceImpl implements SysUserinfoService {
    @Resource
    private SysUserinfoMapper userMapper;
    @Override
    public List<SysUserinfo> getList() {
        return userMapper.selectByExample(null);
    }


    @Override
    public SysUserinfo login(String username, String password) {
        return userMapper.login(username,password);
    }

    @Override
    public SysUserinfo selectId(int id) {
        return userMapper.selectId(id);
    }

    @Override
    public List<Role> getRoleListUser(int uid) {
        return userMapper.getRoleListUser(uid);
    }

    @Override
    public List<Menu> getMenRoleList(String[] roles) {
        return userMapper.getMenuRoleList(roles);
    }

    /**
     * 给用户授权
     * @param uid
     * @param rids
     * @return
     */
    @Override
    public int grantUser(int uid, int[] rids) {
      userMapper.deleteId(uid);
        int count =0;
        for (int d:rids){
            System.out.println(d);
            count+=userMapper.addRole(uid,d);
        }
        return count;
    }

    @Override
    public int deleteId(int uid) {
        return userMapper.deleteId(uid);
    }


}
